package designpattern.factory.absfactory;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Store {
    private static AbsFactory absFactory;

    //出售手机或者路由器
    public void sale() {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            String name = br.readLine();
            if(!name.equals("xm phone") && !name.equals("xm router")
              && !name.equals("hw phone") && !name.equals("hw router")){
                br.close();
                return;
            }
            if(name.contains("xm")){
                absFactory = new XMFactory();
                if(name.contains("phone")){
                    absFactory.productPhone("xm phone");
                }else {
                    absFactory.productRouter("xm router");
                }
            }else{
                absFactory = new HWFactory();
                if(name.contains("phone")){
                    absFactory.productPhone("hw phone");
                }else {
                    absFactory.productRouter("hw router");
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
